<!-- 前端用户列表 -->
<template>
  <div class="table">
    <el-tabs v-model="activeName" @tab-click="handleChangeTabs">
      <el-tab-pane label="用户列表" name="one">
        <SearchTable :selectWhether="selectWhether" ref="searchTableRef" @handleViewEdit="handleViewEdit" />
      </el-tab-pane>
      <el-tab-pane label="用户详情" name="two">
        <FormTab :id="selectId" v-model:formStatus="formStatus" @handleInitData="clearData" @handleSuccess="handleSuccess" />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script setup lang="ts" name="appUserInfo">
import SearchTable from "@/components/user/appUserInfo/SearchTable.vue";
import FormTab from "@/components/user/appUserInfo/FormTab.vue";
import { useDictData } from "@/hooks/network/useDictData";
import type { IDictData } from "@/types/dict";
import type { TabsPaneContext } from "element-plus";
import type { TabsMode, ViewMode, ViewModeFilter } from "@/types/common";

let { getDictData } = useDictData();
/* 表格状态 */
const formStatus = ref<ViewMode>("none");
/* 标签页切换 */
const activeName = ref<TabsMode>("one");
const selectId = ref(0);
/* 表格子组件的引用 */
const searchTableRef = useTemplateRef("searchTableRef");
/* 是否信息 */
const selectWhether = ref<Array<IDictData>>([]);

/* 处理查看编辑 */
function handleViewEdit(id: number, code: ViewModeFilter) {
  selectId.value = id;
  formStatus.value = code;
  activeName.value = "two";
}

/* 处理切换标签页 */
function handleChangeTabs(tab: TabsPaneContext) {
  if (tab.props.name === "two") {
    formStatus.value = "edit";
  } else if (tab.props.name === "one") {
    clearData();
  }
}

/* 清除数据 */
function clearData() {
  selectId.value = 0;
  activeName.value = "one";
  formStatus.value = "none";
}

/* 处理修改成功 */
function handleSuccess() {
  searchTableRef.value?.getTableInfo();
}
/* TODO：还有其他页面跳转进来的情况，到时候兼容 */
// activated() {
//     if (this.$route.params.store_mobile === undefined) return;
//     this.searchCondition.mobile = "";
//     this.searchCondition.store_name = "";
//     this.searchCondition.master_name = "";
//     this.searchCondition.is_cancellation = "";
//     this.searchCondition.store_mobile = this.$route.params.store_mobile;
//     this.searchInfo();
//   }
getDictData("WHETHER", selectWhether);
</script>

<style scoped></style>
